package com.lite.business.entity.retailer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lite.business.entity.DateInterval;
import com.lite.common.entity.QueryConditionWrapper;
import lombok.Builder;
import lombok.Data;

import java.util.Objects;

/**
 * @author Stranger
 * @version 1.0
 * @description: TODO
 * @date 2022/10/25 21:09
 */

@Data
@Builder
public class RetailerQueryWrapper extends QueryConditionWrapper<Retailer> {


    private Retailer retailer;

    /**
     * 时间区间
     */
    private DateInterval dateInterval;

    @Override
    public LambdaQueryWrapper<Retailer> buildWrapper() {
        LambdaQueryWrapper<Retailer> retailerLambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (!Objects.isNull(retailer)) {
            if (!Objects.isNull(retailer.getName())) {
                retailerLambdaQueryWrapper.eq(Retailer::getName, retailer.getName());
            }

            if (!Objects.isNull(retailer.getPhone())) {
                retailerLambdaQueryWrapper.eq(Retailer::getPhone, retailer.getPhone());
            }

            if (!Objects.isNull(retailer.getAddress())) {
                retailerLambdaQueryWrapper.eq(Retailer::getAddress, retailer.getAddress());
            }

            if (!Objects.isNull(retailer.getDeleted())) {
                retailerLambdaQueryWrapper.eq(Retailer::getDeleted, retailer.getDeleted());
            }
        }

        if (!Objects.isNull(dateInterval)) {
            retailerLambdaQueryWrapper
                    .ge(Retailer::getCreatedTime, dateInterval.getBegin()).
                    le(Retailer::getCreatedTime, dateInterval.getEnd());
        }
        return retailerLambdaQueryWrapper;
    }
}
